Muraveva_A_B_queue#140
Hidden character warning
Conversation
|
Поздравляем! Пройден усложненный набор тестов для задачи |
There was a problem hiding this comment.
Pull request overview
Implements the BoundedBlockingQueue<T> lecture task by replacing stubs with a working bounded FIFO queue that blocks producers/consumers using intrinsic monitors (synchronized/wait/notifyAll).
Changes:
- Added internal storage (
Queue<T>) and capacity tracking. - Implemented blocking
put/takewithwait()loops andnotifyAll(). - Implemented
size()andcapacity()plus basic argument validation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public synchronized void put(T item) throws InterruptedException { | ||
| if (item == null) { | ||
| throw new NullPointerException(); | ||
| } | ||
| while (queue.size() == capacity) { | ||
| wait(); | ||
| } | ||
| queue.add(item); | ||
| notifyAll(); | ||
| } | ||
|
|
||
| public T take() throws InterruptedException { | ||
| return null; | ||
| public synchronized T take() throws InterruptedException { | ||
| while (queue.isEmpty()) { | ||
| wait(); | ||
| } | ||
| T item = queue.poll(); | ||
| notifyAll(); | ||
| return item; |
There was a problem hiding this comment.
There are no unit tests covering the blocking/interrupt behavior of this queue implementation (e.g., put blocks when full, take blocks when empty, FIFO ordering, and interruption while waiting). Given the concurrency semantics, adding JUnit tests would help prevent regressions and validate the task requirements.
| public BoundedBlockingQueue(int capacity) { | ||
|
|
||
| if (capacity <= 0) { | ||
| throw new IllegalArgumentException(); |
There was a problem hiding this comment.
Throwing IllegalArgumentException without a message makes it harder to debug invalid usage (e.g., when capacity <= 0). Consider including a short, descriptive message indicating the expected constraint.
| throw new IllegalArgumentException(); | |
| throw new IllegalArgumentException("capacity must be greater than 0: " + capacity); |
|
|
||
| public synchronized void put(T item) throws InterruptedException { | ||
| if (item == null) { | ||
| throw new NullPointerException(); |
There was a problem hiding this comment.
Throwing NullPointerException without a message makes it harder to diagnose which argument was null at call sites. Consider adding a brief message (or using a helper like Objects.requireNonNull) to clarify what was expected.
| throw new NullPointerException(); | |
| throw new NullPointerException("item must not be null"); |
No description provided.